import os
import time

# 运行系统命令
def run_system_cmd(cmd):
    # cmd = "apt-get install -y scrot"  # 假设的安装命令
    res = os.system(cmd)
    print(res)
    if not res:
        print("运行成功!")
        return True
    return False


# 截屏
def print_screen_handle(x, y, w, h, file):
    cmd = f"scrot -a {x},{y},{x+w},{y+h} {file}"
    times = 0
    while times < 3:
        if not run_system_cmd(cmd):
            install_cmd = "apt-get install -y scrot"
            run_system_cmd(install_cmd)
            time.sleep(1)
            times += 1
        else:
            print("截图成功")
            break
